package com.allenkerr.service;

import com.allenkerr.domain.Customer;
import com.allenkerr.domain.CustomerRowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 小柯(Allen Kerr) on 17.5.16 15:38.
 */
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Customer> findAll() {
        System.out.println("findAll方法被调用了！！！");
        String sql = "select * from t_customer";
        List<Customer> customerList = jdbcTemplate.query(sql, new CustomerRowMapper());
        return customerList;
    }

    @Override
    public Customer findById(Integer id) {
        System.out.println("findById方法被调用了！！！");
        String sql = "select * from t_customer where id = ?";
        Customer customer = jdbcTemplate.queryForObject(sql, new CustomerRowMapper(), id);
        return customer;
    }
}
